<?php

class Report extends Controller {

    function Report() {
        parent::Controller();
        $this->load->model('mod_report');
    }

    //======================function for load page muster=======================//
    function index() {
        if($this->check_session()){
        $this->load->view('master');
        }else{
            redirect('admin/');
            exit();
        }
    }

    //======================function is use for loading masgerpage=======================//
    function manager() {
        if($this->check_session()){
        $this->load->view('master');
        }else{
            redirect('admin/');
            exit();
        }
    }

    //======================function is use for loading monthly report======================//
    function monthly() {
        if($this->check_session()){
        $this->load->view('master');
        }else{
            redirect('admin/');
            exit();
        }
    }

    //======================function is use for loading daily report=====================//
    function daily() {
        if($this->check_session()){
        $this->load->view('master');
        }else{
            redirect('admin/');
            exit();
        }
    }

    //======================function is use for loading yearly report=======================//
    function yearly() {
        if($this->check_session()){
        $this->load->view('master');
        }else{
            redirect('admin/');
            exit();
        }
    }

    //============seaching for report===================//
    function find_date_report() {
        if($this->check_session()){
        $date_from = $this->input->post('txt_datestart');
        $date_to = $this->input->post('txt_date_to');
        if ($date_from == '' && $date_to == '') {
            $this->session->set_userdata('valid', '<center style="color:red;">Two text search can not be blank!</center>');
            redirect('report/manager');
        } else if ($date_from > $date_to) {
            $this->session->set_userdata('valid_num', '<center style="color:red;">First Text field must be smaller than the second text field!</center>');
            redirect('report/manager');
        } else {

            $get_report['get_report_value'] = $this->mod_report->select_report();

            $this->load->view('master', $get_report);
        }
        }else{
            redirect('admin/');
            exit();
        }
    }
    function find_date_report1() {
        if($this->check_session()){
        $date_from = $this->input->post('txt_datestart');
        $date_to = $this->input->post('txt_date_to');
        if ($date_from == '' && $date_to == '') {
            $this->session->set_userdata('valid', '<center style="color:red;">Two text search can not be blank!</center>');
            redirect('report/manager');
        } else if ($date_from > $date_to) {
            $this->session->set_userdata('valid_num', '<center style="color:red;">First Text field must be smaller than the second text field!</center>');
            redirect('report/manager');
        } else {

            $get_product['get_report_product'] = $this->mod_report->select_product();

            $this->load->view('master', $get_product);
        }
        }else{
            redirect('admin/');
            exit();
        }
    }
    
    //========this is function for using checking session=============
    
     public function check_session() {
        if ($this->session->userdata('use_username')) {
            return true;
        } else {
            return false;
        }
    }

}